<!DOCTYPE HTML>

<html>
    <head>
        <script type="application/ld+json">
    {
        "@context" : "http://schema.org",
        "@type" : "BlogPosting",
        "mainEntityOfPage": {
             "@type": "WebPage",
             "@id": "\/blog\/"
        },
        "articleSection" : "blog",
        "name" : "模糊搜索及关键词亮高",
        "headline" : "模糊搜索及关键词亮高",
        "description" : "mff的个人博客",
        "inLanguage" : "en",
        "author" : "",
        "creator" : "",
        "publisher": "",
        "accountablePerson" : "",
        "copyrightHolder" : "",
        "copyrightYear" : "2020",
        "datePublished": "2020-05-20 00:00:00 \x2b0000 UTC",
        "dateModified" : "2020-05-20 00:00:00 \x2b0000 UTC",
        "url" : "\/blog\/blog\/%E6%90%9C%E7%B4%A2%E5%8A%9F%E8%83%BD%E5%92%8C%E5%85%B3%E9%94%AE%E8%AF%8D%E4%BA%AE%E9%AB%98\/",
        "wordCount" : "186",
        "keywords" : [ "tutorial","Blog" ]
    }
    </script>
        
            
                <title>模糊搜索及关键词亮高</title>
            
        

        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="generator" content="Hugo 0.69.0" />
        
  
    
  

  

  <link rel="apple-touch-icon-precomposed" href='/blog/favicon/apple-touch-icon-precomposed.png'>
  <link rel="icon" href='/blog/favicon/favicon.png'>
  
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="msapplication-TileImage" content='/favicon/mstile.png'>
  <meta name="application-name" content="mff blog">
  <meta name="msapplication-tooltip" content="">
  <meta name="msapplication-config" content='/favicon/ieconfig.xml'>



        
            <meta name="author" content="mff">
        
        
            <meta name="description" content="mff的个人博客">
        

        <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="模糊搜索及关键词亮高"/>
<meta name="twitter:description" content="mff的个人博客"/>

        <meta property="og:title" content="模糊搜索及关键词亮高" />
<meta property="og:description" content="mff的个人博客" />
<meta property="og:type" content="article" />
<meta property="og:url" content="/blog/blog/%E6%90%9C%E7%B4%A2%E5%8A%9F%E8%83%BD%E5%92%8C%E5%85%B3%E9%94%AE%E8%AF%8D%E4%BA%AE%E9%AB%98/" />
<meta property="article:published_time" content="2020-05-20T00:00:00+00:00" />
<meta property="article:modified_time" content="2020-05-20T00:00:00+00:00" />

        <meta property="og:image" content="/blog//images/logo.png">
        <meta property="og:image:type" content="image/png">
        <meta property="og:image:width" content="512">
        <meta property="og:image:height" content="512">
        <meta itemprop="name" content="模糊搜索及关键词亮高">
<meta itemprop="description" content="mff的个人博客">
<meta itemprop="datePublished" content="2020-05-20T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2020-05-20T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="186">



<meta itemprop="keywords" content="tutorial," />
        

        
            
        

        
        
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-light.min.css">
            <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway:400,800,900|Source+Sans+Pro:400,700">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.css">
            <link rel="stylesheet" href="/blog/css/main.css">
            <link rel="stylesheet" href="/blog/css/add-on.css">
            <link rel="stylesheet" href="/blog/css/academicons.min.css">
        

        
            
                
            
        


  
    
    <link href='//cdn.bootcss.com/highlight.js/9.11.0/styles/github.min.css' rel='stylesheet' type='text/css' />
  


      
    </head>
    <body>

      
      <div id="wrapper">

    
    
<header id="header">
    
      <h1><a href="/blog/">blog</a></h1>
    

    <nav class="links">
        <ul>
            
                <li>
                    <a href="/blog/">
                            <i class="fa fa-home">&nbsp;</i>主页
                    </a>
                </li>
            
                <li>
                    <a href="/blog/blog/">
                            <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                    </a>
                </li>
            
                <li>
                    <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                    </a>
                </li>
            
                <li>
                    <a href="/blog/itemized/">
                            <i class="fa fa-list">&nbsp;</i>最近项目
                    </a>
                </li>
            
                <li>
                    <a href="/blog/contact/">
                            <i class="fa fa-envelope-o">&nbsp;</i>联系我
                    </a>
                </li>
            
        </ul>
    </nav>
    <nav class="main">
        <ul>
            
            <li id="share-nav" class="share-menu" style="display:none;">
                <a class="fa-share-alt" href="#share-menu">Share</a>
            </li>
            
            <li class="search">
                <a class="fa-search" href="#search">Search</a>
                <form id="search" method="get" action="//google.com/search">
                    <input type="text" name="q" placeholder="Search" />
                    <input type="hidden" name="as_sitesearch" value="/blog/">
                </form>
            </li>
            <li class="menu">
                <a class="fa-bars" href="#menu">Menu</a>
            </li>
        </ul>
    </nav>
</header>


<section id="menu">

    
        <section>
            <form class="search" method="get" action="//google.com/search">
                <input type="text" name="q" placeholder="Search" />
                <input type="hidden" name="as_sitesearch" value="/blog/">
            </form>
        </section>

    
        <section>
            <ul class="links">
                
                    <li>
                        <a href="/blog/">
                            <h3>
                                <i class="fa fa-home">&nbsp;</i>主页
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/blog/">
                            <h3>
                                <i class="fa fa-newspaper-o">&nbsp;</i>Blog笔记
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="https://mff-project.gitee.io/hugoblog/posts/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/">
                            <h3>
                                <i class="fa fa-id-card-o">&nbsp;</i>个人简历
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/itemized/">
                            <h3>
                                <i class="fa fa-list">&nbsp;</i>最近项目
                            </h3>
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/contact/">
                            <h3>
                                <i class="fa fa-envelope-o">&nbsp;</i>联系我
                            </h3>
                        </a>
                    </li>
                
            </ul>
        </section>

    
        <section class="recent-posts">
            <div class="mini-posts">
                <header>
                    <h3>Recent Posts</h3>
                </header>
                

                
                    
                

                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-08-27'>
                                    August 27, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-28'>
                                    July 28, 2020</time>
                            </header>
                            

                        </article>
                
                        <article class="mini-post">
                            <header>
                                <h3><a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a></h3>
                                
                                <time class="published" datetime=
                                    '2020-07-26'>
                                    July 26, 2020</time>
                            </header>
                            

                        </article>
                

                
                    <a href=
                        
                            /blog/
                        
                        class="button">View more posts</a>
                
            </div>
        </section>

    
        
</section>

    <section id="share-menu">
    <section id="social-share-nav">
        <ul class="links">
            <header>
                <h3>Share this post <i class="fa fa-smile-o"></i></h3>
            </header>
            



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;text=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;description=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


        </ul>
    </section>
</section>

    
    <div id="main">
        
        
        <article class="post">
  <header>
    <div class="title">
        
            <h1><a href="/blog/blog/%E6%90%9C%E7%B4%A2%E5%8A%9F%E8%83%BD%E5%92%8C%E5%85%B3%E9%94%AE%E8%AF%8D%E4%BA%AE%E9%AB%98/">模糊搜索及关键词亮高</a></h1>
            
        
        
            <p>mff的个人博客</p>
        
    </div>
    <div class="meta">
        

        <time class="published"
            datetime='2020-05-20'>
            May 20, 2020</time>
        <span class="author">mff</span>
        
            <p>1 minute read</p>
        
        
    </div>
</header>


  
    <section id="social-share">
      <ul class="icons">
        



<li>
  <a href="//twitter.com/share?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;text=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98&amp;via=" target="_blank" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
    <p>Twitter</p>
    </a>
</li>




<li>
  <a href="//plus.google.com/share?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn google-plus">
    <i class="fa fa-google-plus"></i>
    <p>Google+</p>
  </a>
</li>





<li>
  <a href="//www.facebook.com/sharer/sharer.php?u=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
    <p>Facebook</p>
    </a>
</li>




<li>
  <a href="//reddit.com/submit?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn reddit">
    <i class="fa fa-reddit-alien"></i>
    <p>Reddit</p>
  </a>
</li>




<li>
  <a href="//www.linkedin.com/shareArticle?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn linkedin">
      <i class="fa fa-linkedin"></i>
      <p>LinkedIn</p>
    </a>
</li>




<li>
  <a href="//www.stumbleupon.com/submit?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;title=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn stumbleupon">
    <i class="fa fa-stumbleupon"></i>
    <p>StumbleUpon</p>
  </a>
</li>




<li>
  <a href="//www.pinterest.com/pin/create/button/?url=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f&amp;description=%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%e5%8f%8a%e5%85%b3%e9%94%ae%e8%af%8d%e4%ba%ae%e9%ab%98" target="_blank" class="share-btn pinterest">
    <i class="fa fa-pinterest-p"></i>
    <p>Pinterest</p>
  </a>
</li>




<li>
  <a href="mailto:?subject=Check out this post by mff&amp;body=%2fblog%2fblog%2f%25E6%2590%259C%25E7%25B4%25A2%25E5%258A%259F%25E8%2583%25BD%25E5%2592%258C%25E5%2585%25B3%25E9%2594%25AE%25E8%25AF%258D%25E4%25BA%25AE%25E9%25AB%2598%2f" target="_blank" class="share-btn email">
    <i class="fa fa-envelope"></i>
    <p>Email</p>
  </a>
</li>


      </ul>
    </section>
  

  

  <div id="content">
    <h3 id="实现前端搜索功能及关键词亮高">实现前端搜索功能及关键词亮高</h3>
<p><img src="/blog/img/imgs/%E5%85%B3%E9%94%AE%E8%AF%8D%E4%BA%AE%E9%AB%98.png" alt="关键词亮高"></p>
<p>当用户搜索一个关键词，到后端进行查询，将查询到用户输入的关键词进行标注</p>
<h3 id="demo">demo</h3>
<p>后端(Django)接参查询数据</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">from</span> rest_framework.views <span style="color:#f92672">import</span> APIView
<span style="color:#f92672">from</span> myapp.models <span style="color:#f92672">import</span> Goods
<span style="color:#f92672">from</span> myapp.myser <span style="color:#f92672">import</span> GoodsSer

<span style="color:#75715e"># 商品列表页</span>
<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">GoodsList</span>(APIView):
    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">get</span>(self,request):
        <span style="color:#75715e"># 检索字段</span>
        text <span style="color:#f92672">=</span> request<span style="color:#f92672">.</span>GET<span style="color:#f92672">.</span>get(<span style="color:#e6db74">&#39;text&#39;</span>,None)
        <span style="color:#75715e"># 模糊查询字段</span>
        goods <span style="color:#f92672">=</span> Goods<span style="color:#f92672">.</span>objects<span style="color:#f92672">.</span>filter(Q(name__contains<span style="color:#f92672">=</span>text) <span style="color:#f92672">|</span> Q(desc__contains<span style="color:#f92672">=</span>text))
        <span style="color:#75715e"># 序列化</span>
        goods_ser <span style="color:#f92672">=</span> GoodsSer(goods,many<span style="color:#f92672">=</span>True)
        <span style="color:#66d9ef">return</span> Response({<span style="color:#e6db74">&#39;data&#39;</span>:goods_ser<span style="color:#f92672">.</span>data})
</code></pre></div><p>前端(vue.js)发送请求并设置亮高(组件myheader.vue)文件</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-vue" data-lang="vue">&lt;<span style="color:#f92672">template</span>&gt;
	&lt;<span style="color:#f92672">div</span>&gt;
    	<span style="color:#75715e">&lt;!--</span> <span style="color:#a6e22e">搜索功能</span> <span style="color:#f92672">--&gt;</span>
        &lt;<span style="color:#f92672">Search</span> <span style="color:#f92672">@search</span><span style="color:#e6db74">=&#34;search&#34;</span> <span style="color:#f92672">v-model</span><span style="color:#e6db74">=&#34;text&#34;</span>&gt;&lt;/<span style="color:#f92672">Search</span>&gt;
    &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
&lt;<span style="color:#f92672">script</span>&gt;
    <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
        <span style="color:#a6e22e">data</span> () {
            <span style="color:#66d9ef">return</span> {
                <span style="color:#75715e">// 搜索关键词变量
</span><span style="color:#75715e"></span>                <span style="color:#a6e22e">text</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;&#39;</span>,
            }
        },
        <span style="color:#75715e">// 监听属性监测页面变化
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">watch</span><span style="color:#f92672">:</span>{
            <span style="color:#a6e22e">$route</span>(<span style="color:#a6e22e">to</span>,<span style="color:#a6e22e">from</span>){
                <span style="color:#75715e">// 手动刷新
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$router</span>.<span style="color:#a6e22e">go</span>(<span style="color:#ae81ff">0</span>);
            }
        },
        <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span>{
            <span style="color:#75715e">// 检索方法
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">search</span><span style="color:#f92672">:</span><span style="color:#66d9ef">function</span>(){
                <span style="color:#75715e">// 进行带参跳转
</span><span style="color:#75715e"></span>                <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$router</span>.<span style="color:#a6e22e">push</span>({<span style="color:#a6e22e">path</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;search&#39;</span>,<span style="color:#a6e22e">query</span><span style="color:#f92672">:</span>{<span style="color:#a6e22e">text</span><span style="color:#f92672">:</span><span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">text</span>}});
            }
        }
    }
&lt;/<span style="color:#f92672">script</span>&gt;
</code></pre></div><p>当获取到用户输入的关键词后，跳转到搜索结果页面(search.vue)文件，记得配置好路由</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-vue" data-lang="vue">&lt;<span style="color:#f92672">template</span>&gt;
	&lt;<span style="color:#f92672">div</span>&gt;
        &lt;<span style="color:#f92672">myheader</span>&gt;&lt;/<span style="color:#f92672">myheader</span>&gt;
        &lt;<span style="color:#f92672">table</span>&gt;
            &lt;<span style="color:#f92672">tr</span> <span style="color:#f92672">v-for</span><span style="color:#e6db74">=&#34;(item,index) in goodslist&#34; </span><span style="color:#f92672">:key</span><span style="color:#e6db74">=&#34;index&#34;</span>&gt;
                &lt;<span style="color:#f92672">td</span>&gt;
                    &lt;<span style="color:#f92672">video</span> <span style="color:#a6e22e">width</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;250&#34;</span> <span style="color:#a6e22e">height</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;250&#34;</span> <span style="color:#f92672">:src</span><span style="color:#e6db74">=&#34;item.video&#34;</span> <span style="color:#a6e22e">controls</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;controls&#34;</span>&gt;&lt;/<span style="color:#f92672">video</span>&gt;
                &lt;/<span style="color:#f92672">td</span>&gt;
                &lt;<span style="color:#f92672">td</span>&gt;
                    &lt;<span style="color:#f92672">div</span> <span style="color:#f92672">v-html</span><span style="color:#e6db74">=&#34;item.name&#34;</span>&gt;&lt;/<span style="color:#f92672">div</span>&gt;
                &lt;/<span style="color:#f92672">td</span>&gt;
                &lt;<span style="color:#f92672">td</span>&gt;
                    &lt;<span style="color:#f92672">span</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;emphasis&#34;</span>&gt;{{ <span style="color:#a6e22e">item</span>.<span style="color:#a6e22e">price</span> }}<span style="color:#960050;background-color:#1e0010">￥</span>&lt;/<span style="color:#f92672">span</span>&gt;
                &lt;/<span style="color:#f92672">td</span>&gt;
            &lt;/<span style="color:#f92672">tr</span>&gt;
        &lt;/<span style="color:#f92672">table</span>&gt;
		
        
    &lt;/<span style="color:#f92672">div</span>&gt;
&lt;/<span style="color:#f92672">template</span>&gt;
&lt;<span style="color:#f92672">script</span>&gt;
    <span style="color:#75715e">//导入组件
</span><span style="color:#75715e"></span>	<span style="color:#66d9ef">import</span> <span style="color:#a6e22e">myheader</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;./myheader.vue&#39;</span>
    <span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> {
        <span style="color:#a6e22e">data</span> () {
            <span style="color:#66d9ef">return</span> {
                <span style="color:#75715e">// 搜索关键词
</span><span style="color:#75715e"></span>                <span style="color:#a6e22e">text</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;&#39;</span>,
                <span style="color:#75715e">// 商品列表
</span><span style="color:#75715e"></span>                <span style="color:#a6e22e">goodslist</span><span style="color:#f92672">:</span>[],
            }
        },
        <span style="color:#75715e">//注册组件标签
</span><span style="color:#75715e"></span>        <span style="color:#a6e22e">components</span><span style="color:#f92672">:</span>{
            <span style="color:#e6db74">&#39;myheader&#39;</span><span style="color:#f92672">:</span><span style="color:#a6e22e">myheader</span>
        },
        <span style="color:#a6e22e">mounted</span><span style="color:#f92672">:</span><span style="color:#66d9ef">function</span>(){
            <span style="color:#75715e">// 接收参数
</span><span style="color:#75715e"></span>            <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">text</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">$route</span>.<span style="color:#a6e22e">query</span>.<span style="color:#a6e22e">text</span>;
            <span style="color:#75715e">// 商品展示
</span><span style="color:#75715e"></span>            <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">get_goods</span>();
        },
        <span style="color:#a6e22e">methods</span><span style="color:#f92672">:</span>{
            <span style="color:#75715e">// 获取商品信息
</span><span style="color:#75715e"></span>            <span style="color:#a6e22e">get_goods</span><span style="color:#f92672">:</span><span style="color:#66d9ef">function</span>(){
                <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">axios</span>.<span style="color:#a6e22e">get</span>(<span style="color:#e6db74">&#39;http://127.0.0.1:8000/goodslist/&#39;</span>,{<span style="color:#a6e22e">params</span><span style="color:#f92672">:</span>{<span style="color:#a6e22e">text</span><span style="color:#f92672">:</span><span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">text</span>}}).<span style="color:#a6e22e">then</span>((<span style="color:#a6e22e">result</span>)=&gt;{
                    <span style="color:#75715e">// 设置关键字亮高
</span><span style="color:#75715e"></span>                    <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">let</span> <span style="color:#a6e22e">i</span><span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;<span style="color:#a6e22e">i</span>&lt;<span style="color:#f92672">result</span><span style="color:#a6e22e">.data.data.length</span><span style="color:#960050;background-color:#1e0010">;</span><span style="color:#a6e22e">i</span><span style="color:#960050;background-color:#1e0010">++)</span>{
                        <span style="color:#a6e22e">result.data.data</span><span style="color:#960050;background-color:#1e0010">[</span><span style="color:#a6e22e">i</span><span style="color:#960050;background-color:#1e0010">][&#39;</span><span style="color:#a6e22e">name</span><span style="color:#960050;background-color:#1e0010">&#39;]</span> <span style="color:#960050;background-color:#1e0010">=</span> <span style="color:#a6e22e">result.data.data</span><span style="color:#960050;background-color:#1e0010">[</span><span style="color:#a6e22e">i</span><span style="color:#960050;background-color:#1e0010">][&#39;</span><span style="color:#a6e22e">name</span><span style="color:#960050;background-color:#1e0010">&#39;]</span><span style="color:#a6e22e">.replace</span><span style="color:#960050;background-color:#1e0010">(</span><span style="color:#a6e22e">new</span> <span style="color:#a6e22e">RegExp</span><span style="color:#960050;background-color:#1e0010">(</span><span style="color:#a6e22e">this.text</span><span style="color:#960050;background-color:#1e0010">,&#39;</span><span style="color:#a6e22e">g</span><span style="color:#960050;background-color:#1e0010">&#39;),&#39;</span>&lt;<span style="color:#f92672">span</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;highlight&#34;</span>&gt;<span style="color:#e6db74">&#39;+this.text+&#39;</span>&lt;/<span style="color:#f92672">span</span>&gt;<span style="color:#960050;background-color:#1e0010">&#39;</span>);
                    };
                    <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">goodslist</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">result</span>.<span style="color:#a6e22e">data</span>.<span style="color:#a6e22e">data</span>;
                })
            }
        }
    } 
&lt;/<span style="color:#f92672">script</span>&gt;
&lt;<span style="color:#f92672">style</span>&gt;
	.<span style="color:#a6e22e">highlight</span>{
		<span style="color:#a6e22e">color</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">rgba</span>(<span style="color:#ae81ff">235</span>, <span style="color:#ae81ff">29</span>, <span style="color:#ae81ff">29</span>, <span style="color:#ae81ff">0.986</span>);
	}
&lt;/<span style="color:#f92672">style</span>&gt;
</code></pre></div>
  </div>

  <footer>
    <ul class="stats">
  <li class="categories">
    <ul>
        
            
            
                <i class="fa fa-folder"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/categories/hugo">Hugo</a></li>
                
            
        
    </ul>
  </li>
  <li class="tags">
    <ul>
        
            
            
                <i class="fa fa-tags"></i>
                
                
                <li><a class="article-category-link" href="/blog/blog/tags/tutorial">tutorial</a></li>
                
            
        
    </ul>
  </li>
</ul>

  </footer>

</article>

    <article class="post">
        <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "shortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
    </article>


<ul class="actions pagination">
    
        <li><a href="/blog/blog/djangomodels%E6%A8%A1%E5%9E%8B%E5%8F%8A%E8%BF%81%E7%A7%BB/"
                class="button big previous">Django模型及迁移文件</a></li>
    

    
        <li><a href="/blog/blog/%E5%8E%9F%E7%94%9Fsql%E5%AE%9E%E7%8E%B0%E5%A4%9A%E9%87%8D%E6%9F%A5%E8%AF%A2/"
                class="button big next">原生sql底层实现多重查询</a></li>
    
</ul>


    </div>
    
<section id="sidebar">

  
  <section id="intro">
    
    
      
        <a href='/blog/'><img src="/blog/img/main/touxiang3.jpg" class="intro-circle" width="150px" alt="Hugo Future Imperfect" /></a>
      
    
    
      <header>
        <h2>mff</h2>
        <p>Effort is for money, and money is life!</p>
      </header>
    
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
  </section>

  
  <section class="recent-posts">
    <div class="mini-posts">
      <header>
        <h3>Recent Posts</h3>
      </header>
      <div class="posts-container">
        

        
          
        

        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/fastdfs%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BB%8B%E7%BB%8D/">FastDFS配置及介绍</a>
              </h3>
              
              <time class="published" datetime='2020-08-27'>
                August 27, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/orm%E5%B8%B8%E8%A7%84%E6%93%8D%E4%BD%9C%E9%87%8D%E7%82%B9/">orm常规操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E6%94%AF%E4%BB%98%E5%AE%9D%E6%B2%99%E7%AE%B1%E6%94%AF%E4%BB%98%E6%93%8D%E4%BD%9C/">支付宝沙箱支付操作</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/%E8%85%BE%E8%AE%AF%E7%9F%AD%E4%BF%A1%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81/">腾讯短信发送验证码</a>
              </h3>
              
              <time class="published" datetime='2020-07-28'>
                July 28, 2020
              </time>
            </header>
            

          </article>
        
          <article class="mini-post">
            <header>
              <h3>
                <a href="/blog/blog/flask&#43;vue%E5%AE%9E%E7%8E%B0%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">flask&#43;vue实现前后端分离</a>
              </h3>
              
              <time class="published" datetime='2020-07-26'>
                July 26, 2020
              </time>
            </header>
            

          </article>
        
      </div>

      
        <a href=
          
            /blog/
          
        class="button">View more posts</a>
      
    </div>
  </section>

  
  
  
  
  
    <section id="categories">
      <header>
        <h3>
          <a href="/blog/categories/">Categories</a>
        </h3>
      </header>
        
          
        

        
        <p>
          <article>
            <header>
              
                <a href="/blog/categories/hugo/">hugo</a>
                <span style="float:right;">43</span>
              
            </header>
          </article>
        </p>
        
    </section>
  
  

  
  
    <section id="mini-bio">
      <h3>About</h3>
      <p>blog于2018年6月10日创建(It was created on May 10, 2020),文章主要介绍了python的一些常用框架和库及它们的一些用法</p>
      <a href="/blog/about/" class="button">Learn More</a>
    </section>
  

  
  <section id="footer">
    
      <ul class="icons">
        
          
    <li><a href="/blog/blog/index.xml" type="application/rss+xml" target="_blank" title="RSS" class="fa fa-rss"></a></li>


        
        












































































  <li><a href="mailto:2980738482@qq.com" title="Email" class="fa fa-envelope"></a></li>


      </ul>
    
    <p class="copyright">
      
        &copy; 2020
        
          mff blog
        
      .
      Powered by <a href="//gohugo.io" target="_blank">Hugo</a>
    </p>
  </section>
</section>

    </div>
    <a id="back-to-top" href="#" class="fa fa-arrow-up fa-border fa-2x"></a>
    

    
      
    

    
      
      
      
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/highlight.min.js"></script>
        
        
        
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/r.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/yaml.min.js"></script>
        <script src="//cdn.bootcss.com/highlight.js/9.11.0/languages/css.min.js"></script>
        <script>hljs.configure({languages: []}); hljs.initHighlightingOnLoad();</script>
      
    
    
    
      <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/skel/3.0.1/skel.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.25/jquery.fancybox.min.js"></script>
      <script src="/blog/js/util.js"></script>
      <script src="/blog/js/main.js"></script>
      <script src="/blog/js/backToTop.js"></script>
    

    
      
        
      
    

    
    <script>hljs.initHighlightingOnLoad();</script>
      <script src="//yihui.name/js/math-code.js"></script>
<script async
src="//cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>


  </body>
</html>

